package com.ybb.account.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ybb.account.entity.MerchantAccountChangeEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface MerchantAccountChangeMapper extends BaseMapper<MerchantAccountChangeEntity> {


    @Insert("insert into ybb_merchant_account_change(code,amount,balance_before,balance_after) values(" +
            "#{code},#{amount}, " +
            "COALESCE((select balance_after from ybb_merchant_account_change b where b.code=#{code} order by b.create_time desc limit 1), 0)," +
            "COALESCE((select balance_after from ybb_merchant_account_change c where c.code=#{code} order by c.create_time desc limit 1), 0)+#{amount}" +
            ")")
    Integer insertChange(@Param("code") String code, @Param("amount") Double amount);
}
